package lambda;


import java.util.function.Consumer;
import java.util.function.Supplier;

public class ExampleMethodReference {
    public static void main(String[] args) {
        // 消费函数式接口
        Consumer<String> consumer1 = new Consumer<>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        consumer1.accept("hello1");

        Consumer<String> consumer2 = s -> System.out.println(s);
        consumer2.accept("hello2");


        Consumer<String> consumer3 = System.out::println;
        consumer3.accept("hello3");

        // 生产函数式接口

        Student student = new Student("张三", 12);
        Supplier<String> supplier1 = new Supplier<String>() {
            @Override
            public String get() {
                return student.getName();
            }
        };
        System.out.println(supplier1.get());

        Supplier<String> supplier2 = () -> student.getName();
        System.out.println(supplier2.get());

        Supplier<String> supplier3 = student::getName;
        System.out.println(supplier3.get());


    }
}
